﻿using System;
using System.Drawing;
using AutoLoL.Logic.Automation;

namespace AutoLoL.Logic
{
    public class ScreenMessage
    {
        public string Message { get; set; }
        public Point Location { get; set; }

        public RectangleF DestRectangle { get; set; }
        public Color BackColor { get; set; }
        public Color TextColor { get; set; }
        public string FontFamily { get; set; }
        public float FontSize { get; set; }
        public FontStyle FontStyle { get; set; }

        public ScreenMessage(string message, Point location)
        {
            Message = message;
            Location = location;
        }

        public ScreenMessage(string message, RectangleF destRectangle, Color backColor, Color textColor, string fontFamily, float fontSize, FontStyle fontStyle)
        {
            Message = message;
            destRectangle.X -= destRectangle.Width / 2;
            destRectangle.Y -= destRectangle.Height / 2;
            DestRectangle = destRectangle;

            BackColor = backColor;
            TextColor = textColor;
            FontFamily = fontFamily;
            FontSize = fontSize;
            FontStyle = fontStyle;
        }

        public void Draw(IntPtr hWnd)
        {
            if (!Location.IsEmpty)
            {
                //////////////////////////////IntPtr dc = Win32.GetWindowDC(hWnd);
                //////////////////////////////Win32.TextOut(dc, Location.X, Location.Y, Message, Message.Length);
                //////////////////////////////Win32.DeleteDC(dc);
                return;
            }

            using (Graphics g = Graphics.FromHwnd(hWnd))
            {
                using (Brush backBrush = new SolidBrush(BackColor))
                {
                    using (Brush textBrush = new SolidBrush(TextColor))
                    {
                        using (Font font = new Font(FontFamily, FontSize, FontStyle))
                        {

                            Bitmap offScreenBmp;
                            Graphics offScreenDC;
                            offScreenBmp = new Bitmap(1000, 1000);
                            offScreenDC = Graphics.FromImage(offScreenBmp);

                            offScreenDC.FillRectangle(backBrush, DestRectangle);
                            offScreenDC.DrawString(Message, font, textBrush, DestRectangle);

                            g.DrawImage(offScreenBmp, 0, 0);
                            //g.FillRectangle(backBrush, DestRectangle);
                            //g.DrawString();
                        }
                    }
                }
            }

        }

        public void Clear(IntPtr hWnd)
        {
            //////////////////////////////Win32.InvalidateRect(hWnd, IntPtr.Zero, true);
        }
    }
}
